﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MMMaze
{
    public static class UIElementExtention
    {
      static  public void MoveControlToTempPlace(this UIElement ui, PlaneProjection targetProjection, TimeSpan time,Action AfterComplete  )
        {
            var dur = new Duration(time);
            var sb = new Storyboard();
            sb.Duration = dur;

            foreach (var dp in targetProjection.GetTypeProperties())
            {
                var ani = new DoubleAnimation();
                ani.Duration = dur;
                sb.Children.Add(ani);
                Storyboard.SetTarget(ani, ui.Projection);
                ani.To = (double)targetProjection.GetValue(dp);
                Storyboard.SetTargetProperty(ani, new PropertyPath(dp));
            }
            if (AfterComplete != null) sb.Completed += new EventHandler((o, e) => {AfterComplete.Invoke(); });
            sb.Begin();



        }

    

    }
}
